package jee.boot.module.bpm.validation;

import jee.boot.entity.bpm.BusinessColumn;

import java.util.List;
import java.util.Map;

/**
 * 数据检查助手
 */
public class DataValidationHelper {
    /**
     * 检查数据
     *
     * @param columnList
     * @param data
     */
    public static void validation(List<BusinessColumn> columnList, Map<String, Object> data) {
        if (columnList != null && !columnList.isEmpty()) {
            for (BusinessColumn column : columnList) {
                String fieldName = column.getFieldName();
                List<String> validations = column.getDataValidation();
                if (validations != null && !validations.isEmpty()) {
                    for (String v : validations) {
                        DataValidation instance = ValidationFactory.getInstance(v);
                        if (instance != null) {
                            instance.validation(data.get(fieldName), fieldName);
                        }
                    }
                }

            }
        }
    }
}
